/**
 * v-throttle
 * 节流
 * 接收参数：string类型/Ref<string>类型/Reactive<string>类型
 */
const throttle = {
	bind(el, binding) {
		if (typeof binding.value !== "function") {
			throw "callback must be a function";
		}
		el.disabled = false;
		let timer = null
		el.__handleClick__ = () => {
			if (!el.disabled) {
				if (timer) {
					clearTimeout(timer);
				}
				el.disabled = true;
				binding.value();
				timer = setTimeout(() => {
					el.disabled = false;
				}, 1000);
			}
		}
		el.addEventListener("click", el.__handleClick__);
	},
	unbind(el) {
		el.removeEventListener("click", el.__handleClick__);
	}
};
export default throttle;